package com.qkst.website.backstage.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.qkst.website.backstage.bean.CatgroupBean;
import com.qkst.website.backstage.bean.CatgroupRelPrdBean;
import com.qkst.website.backstage.mapper.CatgroupMapper;
import com.qkst.website.backstage.mapper.CatgroupRelPrdMapper;
import com.qkst.website.backstage.service.CatgroupService;
/**
 * @author lh
 * @description 产品目录service 业务处理层
 * @date 2017-05-04
 * @email ahlxlihao@163.com
 *
 */
@Service("catgroupService")
@Transactional
public class CatgroupServiceImpl implements CatgroupService {
	@Autowired
	private CatgroupMapper catgroupMapper;
	@Autowired
	private CatgroupRelPrdMapper catgroupRelPrdMapper;

	/**
	 * 获取产品目录
	 * @param catgroup
	 * @return List<CatgroupBean>
	 */
	
	@Override
	public List<CatgroupBean> list(CatgroupBean catgroup) {
		return catgroupMapper.selectCatgroups(catgroup);
	}
	/**
	 * 保存产品目录
	 * @param catgroup
	 * @return CategoryBean
	 */
	@Override
	public CatgroupBean save(CatgroupBean catgroup) {
		catgroup.setCreateTime(new Date());
		catgroup.setLastUpdate(new Date());
		catgroupMapper.insert(catgroup);
		return catgroup;
	}
	
	/**
	 * 删除产品目录
	 * @param catgroup
	 * @return boolean
	 */
	@Override
	public boolean delete(CatgroupBean catgroup) {
		int num=catgroupMapper.deleteByPrimaryKey(catgroup.getCatgroupId());
		if(num>0){
			return true;
		}
		return false;
	}
	/**
	 * 保存分类与属性关系
	 * @param catgroupRelPrd
	 * @return boolean
	 */
	@Override
	public boolean saveCatgroupRelPrd(CatgroupRelPrdBean catgroupRelPrd) {
		int num=catgroupRelPrdMapper.insert(catgroupRelPrd);
		if(num>0){
			return true;
		}
		return false;
	}

}
